﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities.PBCM;

namespace WindowsForms.PBCM
{
    public partial class FormThemDieuLeVaHinhThuc : Form
    {
        public FormThemDieuLeVaHinhThuc()
        {
            InitializeComponent();
        }

        private void buttonThemHinhThucVaDieuLe_Click(object sender, EventArgs e)
        {
            
            try
            {
                DieuLeVaHinhThucThiDau a = new DieuLeVaHinhThucThiDau();
                a.MaDieuLeVaHinhThuc = textBoxMa.Text;
                a.TenDieuLeVaHinhThuc = textBoxTen.Text;
                a.Loai = Convert.ToInt32(textBoxLoai.Text);
                a.TrangThai = Convert.ToInt32(textBoxTrangThai.Text);
                a.IdGiaiDau = Convert.ToInt32(textBoxIDgiaiDau.Text);
                a.NoiDung = textBoxNoiDung.Text;
                if ((a.Loai == 1 || a.Loai == 2)&&(a.TrangThai==1||a.TrangThai==2||a.TrangThai==3))
                {
                    if (DieuLeVaHinhThucThiDau.Objects.Add(a))
                    {
                        MessageBox.Show("Thêm thành công");

                    }
                }
            }

            catch (Exception)
            {
                MessageBox.Show("Thêm không thành công, vui lòng nhập lại");
                //throw;

            }
        }

        private void textBoxTrangThai_KeyPress(object sender, KeyPressEventArgs e)
        {
                if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar)) 
                    e.Handled = true;

        }

        private void textBoxLoai_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
                e.Handled = true;
        }

        private void textBoxIDgiaiDau_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
                e.Handled = true;
        }
    }
}
